<template>
  <div class="customer-list-page">
    <el-card class="customer-card">
      <template #header>
        <div class="card-header">
          <span>客户列表</span>
          <el-button type="primary" @click="handleAdd" v-if="hasPerm('customer:list:add')">新增客户</el-button>
        </div>
      </template>
      
      <el-table :data="customerList" style="width: 100%">
        <el-table-column prop="customerCode" label="客户编号" width="120" />
        <el-table-column prop="customerName" label="客户名称" width="200" />
        <el-table-column prop="contactPerson" label="联系人" width="100" />
        <el-table-column prop="phone" label="联系电话" width="120" />
        <el-table-column prop="email" label="邮箱" width="150" />
        <el-table-column prop="status" label="状态" width="100">
          <template #default="scope">
            <el-tag :type="scope.row.status === 'active' ? 'success' : 'danger'">
              {{ scope.row.status === 'active' ? '启用' : '禁用' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template #default="scope">
            <el-button size="small" @click="handleView(scope.row)" v-if="hasPerm('customer:list:view')">查看</el-button>
            <el-button size="small" type="primary" @click="handleEdit(scope.row)" v-if="hasPerm('customer:list:edit')">编辑</el-button>
            <el-button size="small" type="danger" @click="handleDelete(scope.row)" v-if="hasPerm('customer:list:delete')">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { hasPerm } from '@/utils/permission'
import { ElMessage } from 'element-plus'

const customerList = ref([])

const handleAdd = () => {
  ElMessage.info('新增客户功能')
}

const handleView = (row) => {
  ElMessage.info(`查看客户：${row.customerCode}`)
}

const handleEdit = (row) => {
  ElMessage.info(`编辑客户：${row.customerCode}`)
}

const handleDelete = (row) => {
  ElMessage.info(`删除客户：${row.customerCode}`)
}

onMounted(() => {
  // 模拟数据
  customerList.value = [
    {
      customerCode: 'CUST001',
      customerName: '客户A',
      contactPerson: '张三',
      phone: '13800138001',
      email: 'zhangsan@example.com',
      status: 'active'
    },
    {
      customerCode: 'CUST002',
      customerName: '客户B',
      contactPerson: '李四',
      phone: '13800138002',
      email: 'lisi@example.com',
      status: 'active'
    },
    {
      customerCode: 'CUST003',
      customerName: '客户C',
      contactPerson: '王五',
      phone: '13800138003',
      email: 'wangwu@example.com',
      status: 'inactive'
    }
  ]
})
</script>

<style scoped>
.customer-list-page {
  padding: 20px;
}

.customer-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style> 